-- msg_replay_dungeon_record
-- Created by panyl Mar/03/2016
-- 重播迷宫

return function(lpc)
    local data = lpc.data;
    local dbase = data.dbase;
    local dungeon = data.dungeon;
    local actions = data.actions;

    -- 创建一个玩家
    ME.produceUser(dbase);

    ME.user.achievements = data.achievements;
    ME.user.game_achievement = data.game_achievement;
    ME.user.instance_stat = data.instance_stat;
    DungeonBankM.setExchangeTimes(1, data.exchangeTimes or 0);
    DungeonStatM.updateStat(data.gridStat);
    CombatStatM.updateStat(data.combatStat);
    DungeonDebugM.clear();

    -- 版本号
    ME.user.client_version_record = data.client_version;

    -- 宠物、道具
    local pets = data.pets or {};
    local items = data.items or {};

    -- 1. 道具
    for classId, count in pairs(items) do
        ItemM.updateItem(ME.user, classId, count);
    end

    -- 2. 宠物
    for classId, info in pairs(pets) do
        local career = info.career;
        info.career = nil;

        local pet = Pet.new(classId, info);

        info.career = career;
        pet:restoreData(info);

        ME.user.pets[classId] = pet;
    end

    ME.user.finalData = data.finalData;

    ME.user.msg_list = data.msg_list;

    -- 回放记录
    ME.user.actionRecord = data.actionRecord;
    ME.loginNotifyOk();

    -- 先切换迷宫状态
    DungeonM.switchState(DUNGEON_LEAVE);

    StatusM.apply(ME.user, "PLAYING_RECORD");

    ME.user.replayIndex = 1;
    ME.user.actionProgress = 0;
    ME.user.actionSum = 0;

    for _, action in pairs(data.actionRecord) do
        if action.done then
            ME.user.actionSum = ME.user.actionSum + 1;
        end
    end

    -- 构造迷宫
    DungeonM.notifyDungeonData(dungeon, ME.user.dbase:query("dungeon_context"));
end
